package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import java.util.Map;

/**
 * @program: Spring_day02_01_注解_IoC注解
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-27 16:16
 **/
// @Component
//     @DependsOn("userService")
@PropertySource(value = "classpath:jdbc.properties", ignoreResourceNotFound = false)
public class JDBCConfig {
    @Value("${jdbc.driver}")
    private String driver;

    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.url}")

    private String url;
    @Value("${jdbc.password}")
    private String password;

    private Map map;

    public void setMap(Map map) {
        this.map = map;
    }

    @Bean("dataSource")

    public DruidDataSource getDataSource() {
        System.out.println("dataSource init");
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

}
